using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.ServiceModel;
using log4net;
using log4net.Config;
using Watchdog.Engines;

namespace Watchdog.Dispatcher {
    public partial class Dispatcher : ServiceBase {
        public Dispatcher () {
            InitializeComponent ();
            log = log4net.LogManager.GetLogger ( "servicehost.Logging" );
            scheduleengine = new ScheduleEngine ();
        }
        ILog log;
        ServiceHost serverteamdatahost;
        ServiceHost watchdogdatahost;
        ScheduleEngine scheduleengine;
        protected override void OnStart ( string[] args ) {
            log.Debug ( "service started" );
            // Step 1 : Start the Wcf Dataservices
            serverteamdatahost = new ServiceHost ( typeof ( ServerTeam.Wcf.ServerTeamDataService ) );
            watchdogdatahost = new ServiceHost ( typeof ( Watchdog.Wcf.WatchdogDataService ) );
            serverteamdatahost.Open ();
            watchdogdatahost.Open ();
            scheduleengine.Start ();
        }

        protected override void OnStop () {
            // Step 1 : Stop the Wcf Dataservices
            serverteamdatahost.Close ();
            serverteamdatahost = null;
            watchdogdatahost.Close ();
            watchdogdatahost = null;
            log.Debug ( "service stopped" );
            scheduleengine.Stop ();
        }
    }
}
